.PHONY: build run test clean docker-build docker-run

# 项目配置
BINARY_NAME := alertmanager-webhook
VERSION := 1.0.0
BUILD_TIME := $(shell date +%Y%m%d%H%M%S)
# GIT_COMMIT := $(shell git rev-parse --short HEAD)

# 构建目标
build:
	@echo "Building $(BINARY_NAME)..."
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) " -o $(BINARY_NAME) ./cmd/main.go

# 运行项目
run: build
	@echo "Running $(BINARY_NAME)..."
	./$(BINARY_NAME)

# 测试
test:
	@echo "Running tests..."
	go test -v ./...

# 清理构建文件
clean:
	@echo "Cleaning..."
	rm -f $(BINARY_NAME)
	rm -rf ./logs/*

# Docker构建
docker-build:
	@echo "Building Docker image..."
	docker build -t $(BINARY_NAME):$(VERSION) .

# Docker运行
docker-run:
	@echo "Running Docker container..."
	docker run -d \
	  -p 19093:19093 \
	  --name $(BINARY_NAME) \
	  $(BINARY_NAME):$(VERSION)

# 安装依赖
deps:
	@echo "Installing dependencies..."
	go mod download
	go mod tidy

# 代码格式化
fmt:
	@echo "Formatting code..."
	go fmt ./...